﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Text.RegularExpressions;


namespace Simple_search.Data
{
    public class SearchUnit
    {
        public SearchUnit(string name, string searchTermString, ColorWithBrush markColor)
        {
            Name = name;
            string[] termStrings = searchTermString.Split(',', '，');
            SearchTermString = string.Join(",", termStrings);
            MarkColor = markColor.Color;
            ColorBrush = markColor.Brush;
            foreach (string term in termStrings)
            {
                FuzzyTerms.Add(new Regex(String.Join(".?", term.ToCharArray())));
                Terms.Add(new Regex(term));
            }
        }
        public string Name { get; }
        public string SearchTermString { get; }
        public List<Regex> Terms { get; } = new();
        public List<Regex> FuzzyTerms { get; } = new();
        public Color MarkColor { get; }
        public SolidColorBrush ColorBrush { get; }
        public Dictionary<IBook, List<SearchResult>> Result { get; } = new();

        public void AddResult(IBook book, List<SearchResult> results)
        {
            Result.Add(book, results);
        }

    }

}
